#!/bin/bash

#------------------------------------------------------------------------------
#Filename:      84399-lvm.sh
#Version:       1.0
#Date:          2014/06/23
#Author:        xi.zhang
#Email:         xi.zhang@cs2c.com.cn
#Summary:       02.02系统管理功能-02逻辑卷管理-02字符命令-01创建物理卷
#Notes:         创建物理卷
#Copyright:     China Standard Software Co.,Ltd.
#History:
#               Version 1.0,2014/06/23
#               -The first one
#               Version 1.1,2014/10/22
#               -The second one
#               -Add SFROOT
#               -Add notes
#               -Add CleanData Function
#               -Add trap
#               -Add verification of PV number
#------------------------------------------------------------------------------

if [ -z "$SFROOT" ]
then
    CMDLIB=./
    SFROOT=./
else
    CMDLIB=${SFROOT}/testcases/Management_Function/
fi

. ${SFROOT}/lib/UserOps.sh
. ${CMDLIB}/lib/Partition_parted.sh
. ${CMDLIB}/lib/PV.sh

IsRoot
EchoResult "脚本执行用户为root"

#设置物理卷个数
export PVNUM=3

function CleanData()
{
  EchoInfo "Delete PV"
  DeletePV
}

trap CleanData INT EXIT

GetHarddisk

INIT=`pvs | wc -l`       #系统原有物理卷个数
#echo ${INIT}

#echo y |CreatePV
CreatePV
EchoResult "Step 1 :Create PV"

pvdisplay
EchoResult "Step 2:Display PV property"

END=`pvs | wc -l`
#echo ${END}

#验证物理卷数目
if [ "${INIT}" -eq "0" ]
then 
  ADD=`expr ${END} - ${INIT} - 1`
else
  ADD=`echo "${END}-${INIT}" |bc`
fi
#echo ${ADD}
[ "${ADD}" == "${PVNUM}" ] 
EchoResult "验证成功创建指定数目物理卷"
